package com.ykx.message.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ykx.message.dao.MessageDao;
import com.ykx.message.model.Tmessage;
@Repository("messageDao")
public class MessageDaoImpl implements MessageDao{

	@Autowired
	private SqlSessionTemplate  sqlSession;
	
	public void insert(Tmessage message) throws Exception {
		// TODO Auto-generated method stub
		sqlSession.insert("com.ykx.message.dao.MessageDao.insert",message);
	}

	public void update(Tmessage message) throws Exception {
		// TODO Auto-generated method stub
		sqlSession.update("com.ykx.message.dao.MessageDao.update",message);
	}

	public Tmessage getMessage(String messageId, String consumerQueue) throws Exception {
		Map<String,String> map = new HashMap<String,String>();
		map.put("messageId", messageId);
		map.put("consumerQueue", consumerQueue);
		
		return sqlSession.selectOne("com.ykx.message.dao.MessageDao.getMessage", map);
	}

	public void remove(String messageId, String consumerQueue) throws Exception {
		// TODO Auto-generated method stub
		Map<String,String> map = new HashMap<String,String>();
		map.put("messageId", messageId);
		map.put("consumerQueue", consumerQueue);
		sqlSession.delete("com.ykx.message.dao.MessageDao.remove", map);
	}

	public List<Tmessage> getMessageListTimeOut(String status, int batchSize) throws Exception {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("status", status);
		map.put("batchSize", batchSize);
		return sqlSession.selectList("com.ykx.message.dao.MessageDao.getMessageListTimeOut", map);
	}

}
